#include "makeFileOfLargeNum.h"

void CreateNumFile(const int n)
{
	FILE* fp = fopen("large_num.txt", "w");
	if (fp == NULL) { perror("CreateNumFile::fopen is default!"); return; }

	int* arr = (int*)malloc(sizeof(int) * n);
	srand(time(0));
	for (int i = 0; i < n; i++)
	{
		arr[i] = ((rand() % INT_MAX) + i) % 50000;
		fprintf(fp, "%d\n", arr[i]);
	}

	free(arr);
	fclose(fp);
}

int* ReadNumFile(const char* file_name, const int n)
{
	FILE* fp = fopen(file_name, "r");
	if(fp == NULL){ perror("ReadNumFile::fopen is default!"); return NULL; }

	int* arr = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		if (fscanf(fp, "%d", (int*)((char*)arr + i * sizeof(int))) == EOF) { break; }
	}

	fclose(fp);
	return arr;
}